home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 6.0 KB | 201 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWDelSta.h
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWDELSTA_H
- #define FWDELSTA_H
-
- #ifndef FWEXCTAS_H
- #include "FWExcTas.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWEXCRUN_H
- #include "FWExcRun.h"
- #endif
-
- #ifndef FWCLAINF_H
- #include "FWClaInf.h"
- #endif
-
- class _FW_CDeleteStack;
- class _FW_CDeleteEntry;
- class _FW_CAutoDestructObject;
-
- //========================================================================================
- // CLASS _FW_CDeleteEntry
- //========================================================================================
-
- class _FW_CDeleteEntry
- {
- public:
-
- enum __DeleteType
- {
- __kObject,
- __kGuard,
- __kDeleted,
- __kInvalid
- };
-
- __DeleteType fType;
- union
- {
- _FW_CAutoDestructObject * fObject;
- FW_ClassReference fGuard;
- };
-
- void *fObjectVTable; // The objects v table at time of construction
-
- _FW_CDeleteEntry(_FW_CAutoDestructObject * anObject);
- _FW_CDeleteEntry(FW_ClassReference guard);
-
- __DeleteType GetType();
- void SetType(__DeleteType type);
- FW_ClassReference GetGuard();
- _FW_CAutoDestructObject *GetObject();
- };
-
-
- //========================================================================================
- // CLASS _FW_CDeleteStack
- //
- // The delete stack is maintained as an array of pointers to DeleteEntry, and three
- // pointers into the array. The three pointers are the StackBase, StackTop, and
- // StackLimit. The StackBase points to the beginning of the array, the StackLimit points
- // one past the last position in the array, and the StackTop points one past the last
- // pushed item. When the stack is empty, StackBase == StackTop. When the stack is
- // full StackTop == StackLimit. If an item is pushed when the stack is full, it is
- // resized, which may move the array, so all three pointers need to be updated. To do
- // this, an integer offset RelativeTopOfStack is sometimes used to remember the location
- // of a StackTop across code that might resize the stack.
- //
- // Class Invariants:
- // GetStackBase() != NULL
- // GetStackBase() <= GetStackTop() <= GetStackLimit()
- // GetStackTop() == GetStackBase() + RelativeTopOfStack()
- // GetStackBase() + GetCurrentStackSize() == GetStackLimit()
- //========================================================================================
-
- class _FW_CDeleteStack
- {
- public:
- static void Initialize(FW_SPrivExceptionGlobals& globals);
- static void Terminate();
-
- static inline void Push(_FW_CAutoDestructObject* anObject);
- static inline void Push(FW_ClassReference aGuard);
-
- static int IsClassExpectedInContext(_FW_CTryBlockContext *context, FW_ClassReference thrownType);
- // Search for a guard that would prevent throwing this class to the next context.
- // If we don't find such a guard then return true otherwise return false.
-
- static void PopOffAndDeleteObjectsInContext(FW_SPrivExceptionGlobals& globals,
- _FW_CTryBlockContext *context);
- static _FW_StackEntries RelativeTopOfStack(FW_SPrivExceptionGlobals& globals);
- static void PopIfTopEquals(_FW_CAutoDestructObject* anObject);
- static FW_ClassReference PopGuard();
-
- private:
- static void Push(void * aGuardOrObject, _FW_CDeleteEntry::__DeleteType deleteType);
-
- enum
- {
- kNumberOfObjectsToGrowStack = 256,
- kStepByteSize = kNumberOfObjectsToGrowStack * sizeof(_FW_CDeleteEntry)
- };
-
- static void SetStackTop(FW_SPrivExceptionGlobals& globals, _FW_CDeleteEntry * pStackTop);
-
- #ifdef FW_DEBUG
- static void CheckClassInvariants(FW_SPrivExceptionGlobals& globals);
- #endif
- };
-
- //========================================================================================
- // STRUCT _FW_SThrowGuard
- //========================================================================================
-
- struct _FW_SThrowGuard
- {
- #ifdef FW_DEBUG
- FW_ClassReference fGuardClass;
- #endif
- _FW_SThrowGuard();
- _FW_SThrowGuard(FW_ClassReference guard);
- ~_FW_SThrowGuard();
- };
-
- //========================================================================================
- // CLASS _FW_CDeleteEntry INLINE Functions
- //========================================================================================
-
- inline _FW_CDeleteEntry::__DeleteType _FW_CDeleteEntry::GetType()
- {
- return fType;
- }
-
- inline void _FW_CDeleteEntry::SetType(__DeleteType type)
- {
- fType = type;
- }
-
- inline FW_ClassReference _FW_CDeleteEntry::GetGuard()
- {
- FW_PRIV_ASSERT(fType == __kGuard);
- return fGuard;
- }
-
- inline _FW_CAutoDestructObject *_FW_CDeleteEntry::GetObject()
- {
- FW_PRIV_ASSERT(fType == __kObject);
- return fObject;
- }
-
- //========================================================================================
- // CLASS _FW_CDeleteStack INLINE Functions
- //========================================================================================
-
- inline void _FW_CDeleteStack::SetStackTop(FW_SPrivExceptionGlobals& globals,
- _FW_CDeleteEntry* pStackTop)
- {
- #ifdef FW_DEBUG
- pStackTop->SetType(_FW_CDeleteEntry::__kInvalid);
- #endif
- globals.gStackTop = pStackTop;
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_CDeleteStack::RelativeTopOfStack
- //----------------------------------------------------------------------------------------
- inline _FW_StackEntries _FW_CDeleteStack::RelativeTopOfStack(FW_SPrivExceptionGlobals& globals)
- {
- return globals.gStackTop - globals.gStackBase;
- }
-
- //========================================================================================
- // CLASS _FW_CDeleteStack INLINE Functions (Platform independent versions)
- //========================================================================================
-
- inline void _FW_CDeleteStack::Push(FW_ClassReference aGuard)
- {
- Push((void*) aGuard, _FW_CDeleteEntry::__kGuard);
- }
-
- inline void _FW_CDeleteStack::Push(_FW_CAutoDestructObject* anObject)
- {
- Push((void*) anObject, _FW_CDeleteEntry::__kObject);
- }
-
- #endif
-